import axios from 'axios';

const API_URL = 'http://10.243.113.6:11434'; // Ollama API 地址

export const sendMessageToOllama = async (userInput) => {
  try {
    const response = await axios.post(`${API_URL}/api/chat`, {
      messages: [
        {
          role: "user",
          content: userInput
        }
      ],
      model: "qwen2:7b",
      stream: false,
      temperature: 0.01,
      max_tokens: 1024
    });

    // 返回 API 返回的 assistant 消息内容
    return response.data.message.content; // 假设 API 返回的消息在 message.content 字段中
  } catch (error) {
    console.error('Ollama API 调用失败:', error);
    throw error; // 抛出错误以便在调用处处理
  }
}; 